﻿using System;
using System.IO;
using System.Web;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using XWG.Framework.AuthUtility;
using XWG.JWBST.JWBSTEntity;
using XWG.JWBST.ProcessInterfaces;

//接口废弃  2013年7月17日 14:46:21
namespace XWG.JWBST.LetterReportProcess
{
    /// <summary>
    /// 信访举报   01:信访投诉 02：群众建议 
    /// </summary>
    public class Process : IProcess
    {
        /// <summary>
        /// 信访举报
        /// </summary>
        /// <param name="reader">接受数据</param>
        /// <param name="context">请求信息</param>
        /// <returns>操作结果</returns>
        public string ProcessData(StreamReader reader, HttpContext context)
        {
            //读取提交数据
            string receivemes = reader.ReadToEnd();

            // UrlDecode解码
            receivemes = HttpUtility.UrlDecode(receivemes);

            //反序列化Json对象
            JObject jo = (JObject)JsonConvert.DeserializeObject(receivemes);
            TbBstComplain ok = new TbBstComplain();
            ok.UserId = jo["userID"].ToString().Replace("\"", string.Empty);
            ok.PhoneNo = jo["phone"].ToString().Replace("\"", string.Empty);
            ok.ComplainTitle = jo["title"].ToString().Replace("\"", string.Empty);
            ok.ComplainType = jo["type"].ToString().Replace("\"", string.Empty);
            ok.ComplainContent = jo["content"].ToString().Replace("\"", string.Empty);
            ok.ComplaiDate = DateTime.Now;
            ok.ComplainPkid = Guid.NewGuid().ToString();

            //执行数据库插入操作
            ResultModel resultModel = XWG.JWBST.JWBSTBLL.TbBstComplainBLL.Insert(ok,string.Empty, false);

            //返回结果
            return resultModel.Message;

            #region
            //string receivemes = HttpUtility.UrlDecode(reader.ReadToEnd());
            //int star = receivemes.IndexOf("{");
            //string onKey = receivemes.Remove(0, star);
            //JObject Com = (JObject)JsonConvert.DeserializeObject(onKey);

            //TbBstComplain Complain = new TbBstComplain();
            //Complain.ComplainPkid = Guid.NewGuid().ToString();
            //Complain.UserId = Com["ID"].ToString().Replace("\"", "").Trim();
            //Complain.PhoneNo = Com["phone"].ToString().Replace("\"", "").Trim();
            //Complain.ComplainType = Com["type"].ToString().Replace("\"", "").Trim();
            //Complain.ComplainTitle = Com["title"].ToString().Replace("\"", "").Trim();
            //Complain.ComplainContent = Com["content"].ToString().Replace("\"", "").Trim();
            //Complain.ComplaiDate = System.DateTime.Now;

            //return  JsonConvert.SerializeObject(XWG.JWBST.JWBSTBLL.TbBstComplainBLL.Insert(Complain, "", false))

            #endregion
        }
    }
}
